import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { map } from 'rxjs/operators';
import { Observable } from 'rxjs';
import { UserManageService } from '../user-manage/user-manage.service';
import { DictionaryManageService } from '../dictionary-manage/dictionary-manage.service';

@Injectable({
    providedIn: 'root'
})
export class AuditManageService {

    baseUrl: string = "/api/audit"

    constructor(
        private http: HttpClient,
        private userService : UserManageService,
        private dictionaryService : DictionaryManageService
    ) { }

    apiList(data): Observable<any> {
        let _dataJson = {
            params: {
                ...data,
                page: data.page - 1
            },

        }
        return this.http.get(this.baseUrl, _dataJson)
    }
    apiLevel(name){
        let _dataJson = {
            dictName : name,
        }
        return this.dictionaryService.getDetailAll(_dataJson)
    }
    apiSave(data): Observable<any> {
        let _dataJson = {
            ...data
        }
        return this.http.post(this.baseUrl, _dataJson)
    }
    apiDelete(data): Observable<any> {
        let _dataJson = {
            headers: new HttpHeaders({
                'Content-Type': 'application/json',
            }),
            body: data
        }
        return this.http.delete(this.baseUrl, _dataJson)
    }
    apiEdit(data): Observable<any> {
        let _dataJson = {
            ...data
        }
        return this.http.put(this.baseUrl, _dataJson)
    }
    apiGetUser() : Observable<any>{
        let _dataJson = {
            size : 1000000,
            page : 0,
        }
        return this.userService.getDepartMember(_dataJson)
    }
}
